package com.sd.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.sd.dao.UserInfo;
import com.sd.util.EncryptMD5Utils;

public class LoginService {

	public static Map<String, Object> check(String userName, String password, String securityCode,
			String sessionSecurityCode) {
		Map<String, Object> map = new HashMap<String, Object>();
		UserInfo userInfo;
		if (userName == null || userName.equals("")) {
			map.put("result", "false");
			map.put("message", "用户名为空！");
			return map;
		} else if (password == null || password.equals("")) {
			map.put("result", "false");
			map.put("message", "用户密码为空！");
			return map;
		}

		String sql = "SELECT * FROM user_info WHERE username=?";
		List<UserInfo> list = UserInfo.dao.find(sql, userName);
		if (list.size() == 1) {
			userInfo = list.get(0);
			String md5Password = EncryptMD5Utils.capital32MD5(password);
			if (md5Password.equals(userInfo.getUserPassword())) {
				map.put("result", "true");
				map.put("userInfo", userInfo);
			} else {
				map.put("result", "false");
				map.put("message", "用户名或密码错误！");
			}
		} else {
			map.put("result", "false");
			map.put("message", "用户名或密码错误！");
		}
		return map;
	}
}
